package com.aierjun.lgmusic.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.aierjun.lgmusic.R;
import com.aierjun.lgmusic.entity.NewEntity;
import com.aierjun.lgmusic.utils.TimeUtil;

import java.util.List;

/**
 * Created by Administrator on 2016/10/11.
 */
public class NewsAdapter extends BaseAdapter {
    private Context context;
    private List<NewEntity> entityList;

    public NewsAdapter(Context context, List<NewEntity> entityList) {
        this.context = context;
        this.entityList = entityList;
    }

    @Override
    public int getCount() {
        return entityList.size();
    }

    @Override
    public Object getItem(int position) {
        return entityList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHOlder viewHOlder;
        if (convertView==null){
            viewHOlder=new ViewHOlder();
            convertView=View.inflate(context, R.layout.priselist,null);
            viewHOlder.userName= (TextView) convertView.findViewById(R.id.tv_share_info);
            viewHOlder.time= (TextView) convertView.findViewById(R.id.tv_upload_date);
            viewHOlder.musicName= (TextView) convertView.findViewById(R.id.tv_music_name);
            viewHOlder.musicAnthor= (TextView) convertView.findViewById(R.id.tv_singer);
            viewHOlder.zan= (TextView) convertView.findViewById(R.id.zan_item);
            viewHOlder.mes= (TextView) convertView.findViewById(R.id.mes_item);
            convertView.setTag(viewHOlder);
        }else {
            viewHOlder= (ViewHOlder) convertView.getTag();
        }
        NewEntity newEntity= (NewEntity) getItem(position);
        viewHOlder.userName.setText(newEntity.getLogin_name());
        viewHOlder.userName.setTextColor(context.getResources().getColor(R.color.color_red));
//        viewHOlder.time.setText(TimeUtil.getInstance().getTime()+"");
        viewHOlder.musicName.setText(newEntity.getSong_name());
        viewHOlder.musicAnthor.setText(newEntity.getMusician_name());
        viewHOlder.zan.setText(newEntity.getLike_count()+"");
        viewHOlder.mes.setText(newEntity.getComment_count()+"");

//        viewHOlder.userName.setText("haha");
        viewHOlder.time.setText("hehe");
//        viewHOlder.musicName.setText("woow");
//        viewHOlder.musicAnthor.setText("jajd");
//        viewHOlder.zan.setText("djad");
//        viewHOlder.mes.setText("djaljd");
        return convertView;
    }
    class ViewHOlder{
        TextView userName;
        TextView time;
        TextView musicName;
        TextView musicAnthor;
        TextView zan;
        TextView mes;
        ImageView userIcon;
        ImageView musicImg;
    }
}
